<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types = 1);

namespace app\api\controller\ding;

use app\api\controller\Controller;
use app\api\model\ding\OrderSeat as OrderSeatModel;
use app\api\model\ding\Seat as SeatModel;
use app\api\model\ding\SeatCategory as SeatCategoryModel;
use app\api\service\User as UserService;
use cores\exception\BaseException;
use think\facade\Db;
use think\response\Json;

/**
 *
 * Class Cart
 * @package app\api\controller
 */
class Seat extends Controller {
	/**
	 * 餐位列表
	 * @return Json
	 * @throws BaseException
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\DbException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \cores\exception\BaseException
	 */
	public function list(int $categoryId): Json {

		$shopId = $params['shopId'];

		$service = new SeatModel;
		$params = $this->request->param();
		$list = $service->getList($categoryId, $shopId);

		return $this->renderSuccess(compact('list'));
	}
	public function listAll(int $categoryId,int $shopId): Json {
		


		$service = new SeatModel;
		$params = $this->request->param();
		$list = $service->getListAll($categoryId, $shopId);

		return $this->renderSuccess(compact('list'));
	}
	/*
		*预订晴雨表
	*/
	public function getWeatherList(int $shopId): Json {
		


		$service = new OrderSeatModel;
		$list = $service->getWeatherList($shopId);

		return $this->renderSuccess(compact('list'));
	}
	/*
		*餐厅预订实时数据
	*/
	public function getRealTimeList($type = 1,int $shopId): Json {
		$user = UserService::getCurrentLoginUser(true);


		$service = new OrderSeatModel;
		$time = Date('Y-m-d');
		$time = $time . ' 14:30';
		if (time() > strtotime($time)) {
			$type = 2; //晚餐
		} else {
			$type = 1;
		}

		$list = $service->getRealTimeList($shopId);
		return $this->renderSuccess(compact('list', 'type'));
	}

	/*
		*门店预订数据台
	*/
	public function getOrderData($date = 0,int $shopId): Json {



		$service = new OrderSeatModel;
		$list = $service->getOrderData($shopId, $date);

		return $this->renderSuccess(compact('list'));
	}

	/*
		*餐位排行
	*/

	public function rankList(int $shopId=0): Json {
	
		

		$service = new SeatModel;
		$params = $this->request->param();
		$list = $service->getListRank($shopId, $params);

		return $this->renderSuccess(compact('list'));
	}

	/**
	 * 列表
	 * @return Json
	 * @throws BaseException
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\DbException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \cores\exception\BaseException
	 */
	public function listYuding(): Json {
		
		$service = new SeatCategoryModel;
		$params = $this->request->param();
		$list = $service->getListYuding((int)$params['shopId'], $params);

		return $this->renderSuccess(compact('list'));
	}
	/**
	 * 转台餐位列表
	 * @return Json
	 * @throws BaseException
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\DbException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \cores\exception\BaseException
	 */
	public function listChange(): Json {
		
		$params = $this->request->param();
		$shopId = $params['shopId'];

		$service = new SeatCategoryModel;
		
		$list = $service->getListChange((int)$shopId, $params);

		return $this->renderSuccess(compact('list'));
	}

	/**
	 * 列表-安排落座
	 * @return Json
	 * @throws BaseException
	 * @throws \think\db\exception\DataNotFoundException
	 * @throws \think\db\exception\DbException
	 * @throws \think\db\exception\ModelNotFoundException
	 * @throws \cores\exception\BaseException
	 */
	public function listYuyue(): Json {
	
	
		$service = new SeatCategoryModel;
		$params = $this->request->param();
		$shopId = $params['shopId'];
		$list = $service->getListYuyue((int)$shopId, $params);

		return $this->renderSuccess(compact('list'));
	}

	public function add(): Json {
		$model = new SeatModel;
	
		$model->add($this->postForm());
		return $this->renderSuccess([], '保存成功');
	}
	public function edit(int $seatId): Json {
		$model = new SeatModel;
		$detail = SeatModel::detail($seatId);

		$detail->edit($this->postForm());
		return $this->renderSuccess([], '保存成功');
	}
	public function del(int $seatId): Json {
		$model = new SeatModel;
		$detail = SeatModel::detail($seatId);
		$detail->remove();
		return $this->renderSuccess([], '删除成功');
	}
	public function detail(int $seatId) {
		$detail = SeatModel::detail($seatId, ['images.file', 'image', 'tags']);
		return $this->renderSuccess(compact('detail'));
	}

}
